package com.yonyou.openapi.base.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yonyou.openapi.base.exception.BusinessException;

/**
 * @author nishch
 * @description:
 * @date 2023/8/24
 */
public class JSONConvertUtil {

    public static String convertString(Object object){
        try {
            if(object!=null){
                ObjectMapper objectMapper = new ObjectMapper();
                objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
                return objectMapper.writeValueAsString(object);
            }
        }catch (Exception exception){
            throw  new BusinessException("JSON转换异常");
        }
        return null;
    }
}
